<template>
  <div class="content-Log">
    <div class="form-auth-key">
      <Form :model="formAuthKey" label-position="left" :label-width="100">
        <FormItem label="采集站编号">
          <Input v-model="formAuthKey.site_code"></Input>
        </FormItem>
        <FormItem label="请求标识">
          <Input v-model="formAuthKey.request_identity"></Input>
        </FormItem>
        <FormItem label="标识">
          <Input v-model="formAuthKey.id"></Input>
        </FormItem>
        <FormItem label="类型">
          <Select v-model="formAuthKey.type">
            <Option value="0">采集站日志</Option>
            <Option value="1">用户操作日志</Option>
            <Option value="2">采集站调用管理平台接口日志</Option>
            <Option value="3">第三方调用采集站日志</Option>
          </Select>
        </FormItem>
        <FormItem label="用户">
          <Input v-model="formAuthKey.user"></Input>
        </FormItem>
        <FormItem label="日志产生时间">
          <Input v-model="formAuthKey.time" placeholder="格式：2019-07-12 12:18:00"></Input>
        </FormItem>
        <FormItem label="URL">
          <Input v-model="formAuthKey.jk_url"></Input>
        </FormItem>
        <FormItem label="操作类型">
          <Input v-model="formAuthKey.operation_type"></Input>
        </FormItem>
        <FormItem label="操作内容">
          <Input  v-model="formAuthKey.operation_content" type="textarea"></Input>
        </FormItem>
        <FormItem label="认证码">
          <Input v-model="formAuthKey.auth_key"></Input>
        </FormItem>
        <FormItem>
          <Button type="primary" @click="handleApiAuthKey()">发送</Button>
        </FormItem>
      </Form>
    </div>
    <div class="panel-auth-key-request-param">
      请求参数：
      <div><pre>{{ this.formAuthKey }}</pre></div>
    </div>
    <div class="panel-auth-key-response-param" v-show="rsShow">
      响应参数({{this.spendTime}} 秒)：
      <div><pre>{{ this.responseParam }}</pre></div>
    </div>
  </div>
</template>

<script>
import { apiLog } from '@/api/SiteApiTest'
import {apiResult} from "@/libs/util";
export default {
  name: 'Log',
  data () {
    return {
      formAuthKey: {
        site_code: '',
        request_identity: '',
        id: '',
        type: '',
        user: '',
        time: '',
        jk_url: '',
        operation_type: '',
        operation_content: '',
        auth_key: ''
      },
      requestParam: '',
      responseParam: '',
      spendTime: 0,
      rsShow: false
    }
  },
  methods: {
    handleApiAuthKey () {
      this.requestParam = JSON.stringify(this.formAuthKey)
      apiLog(this.requestParam).then(res => {
        apiResult(res.data,false,result=>{
          this.spendTime = res.data.data.spendTime
          this.responseParam = JSON.parse(res.data.data.rs)
          this.rsShow = true
        })
      })
    }
  }
}
</script>

<style lang="less">
@import "./Log";
</style>
